#include <iostream>
#include <cmath>

using namespace std;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		int a[n];
		for(int i = 0; i < n; ++i){
			cin >> a[i];
		}
		
		int r = n-1;
		int ret = 0;
		while(r >= 1){
			while(r >= 1 && a[r-1] <= a[r]){
				--r;
			}
			int maxi = 0;
			int l = r-1;
			while(l >= 0 && a[l] >= a[r]){
				maxi = max(a[l],maxi);
				--l;
			}
			ret = max(ret,maxi-a[r]);
			r = l;
		}
		
		cout << ret;
		if(t) cout << endl;
	}

	return 0;
}

